package edu.tyut.game.ui.game

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import edu.tyut.game.R
import edu.tyut.game.databinding.FragmentGameBinding
import edu.tyut.game.logic.model.Game
import edu.tyut.game.ui.learn.LearnViewModel
import java.net.Socket

class GameFragment : Fragment() {

    private var _binding: FragmentGameBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    private val viewModel by lazy {
        ViewModelProvider(this)[GameViewModel::class.java]
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {

        _binding = FragmentGameBinding.inflate(inflater, container, false)
        val root: View = binding.root

        // 添加游戏
        val gridLayoutManager = GridLayoutManager(this.requireContext(), 2, RecyclerView.VERTICAL, false)
        gridLayoutManager.orientation = RecyclerView.VERTICAL
        binding.recyclerView.layoutManager = gridLayoutManager
        val gameList = mutableListOf(Game(R.drawable.fly_flower_order, "飞花令"))
        binding.recyclerView.adapter = GameAdapter(this.requireContext(), gameList)


        return root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}